<template>
  <div>
    <!-- 面包屑 -->
    <div class="home-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item >知识图库</el-breadcrumb-item>
        <el-breadcrumb-item >事理查询</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="entityquery-content">
      <div class="entityquery-content-header">
        <!-- 查询实体 -->
        <el-input v-model="queryForm.entity1" placeholder="查询事件1" :style="{width:200+'px'}"></el-input>
        <i class="iconfont" @click="changeVlaue"><el-link type="primary" :underline="false">&#xe658;</el-link></i>
        <!-- 查询实体2 -->
        <el-input placeholder="查询事件2" v-model="queryForm.entity2" :style="{width:300+'px'}">
          <el-button slot="append" type="primary" @click="entityQuery">查询</el-button>
        </el-input>
      </div>


      <div class="entityquery-content-title">
        <span>热门搜索：</span>
        <el-link type="primary" :underline="false" v-for="item in this.hotTopList" :key="item" @click="clickQuery(item)">{{item}}</el-link>&emsp;
      </div>

      <div class="entityquery-content-chart">
        <!-- 关系图 -->
        <div  style="height: 500px;">
          <span>事理逻辑图：</span>
          <div style="height: 470px;">
            <affairquery-echarts :chartsData="chartsData"></affairquery-echarts>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import KMaintainApi from '@/api/kMaintainApi'
  import AffairqueryEcharts from './echarts/affairQueryEcharts'
  export default{
    name:"实体查询",
    data(){
      return{
        input3:"",
        // 图表数据
        chartsData:{},
        // 查询form
        queryForm:{
          entity1:'',
          entity2:''
        },
        // 热门搜索
        hotTopList:[]
      }
    },
    components:{
      AffairqueryEcharts
    },
    created() {
      KMaintainApi.medAnswerTop('logic').then(res => {
        if(res.data.status === "200"){
          // 拼接字符串
          res.data.data.records.map(val => {
            var  str = val.entity1 + "--->" + val.entity2
            this.hotTopList.push(str)
          })
        }
      })
    },
    methods:{
      // 事理查询
      entityQuery(){
        KMaintainApi.affairQuery(this.queryForm).then(res => {
          if(res.data.status === "200"){
            this.chartsData = res.data.data
            // 将实体二存下
            this.chartsData.entity = this.queryForm.entity1
          }
        })
      },
      //数值更换
      changeVlaue(){
        var temp = ''
        temp = this.queryForm.entity1
        this.queryForm.entity1 = this.queryForm.entity2
        this.queryForm.entity2 = temp
      },
      // 点击查询
      clickQuery(info){
        // 拆分字符串
        var queryInfo = info.split("--->")
        // 发送请求
        this.queryForm.entity1 = queryInfo[0]
        this.queryForm.entity2 = queryInfo[1]
        
        this.entityQuery()
      }
    }
  }
</script>

<style scoped="scoped">
  .el-button{
    border-radius: 0px;
  }
  .entityquery-content{
    background-color: #FFFFFF;
    border-radius: 8px;
    padding: 20px;
  }
  .entityquery-content-title{
    padding: 10px;
    color: rgb(98, 98, 98);
    border-bottom: 1px solid #DCDFE6;
  }
  .entityquery-content-title a{
    margin-right: 30px;
  }
  .entityquery-content-title span:nth-child(2){
    color: rgb(26, 175, 241);
  }
  .entityquery-content-chart{
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    /* align-items: center; */
    /* height: 300px; */
  }
  .entityquery-content-chart div:nth-child(1){
    flex: 3;
    /* height: 100%; */
    display: flex;
    flex-direction: column;
    border: 1px solid #C0C4CC;
  }
  .entityquery-content-chart div span{
    display: block;
    height: 40px;
    line-height: 40px;
    padding-left: 20px;
    background-color: rgb(245, 245, 245);
    box-shadow: 1px 1px 5px #909399;
  }
  .entityquery-content-header{
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .entityquery-content-header a{
    font-size: 30px;
    margin: 0 20px;
    color: #409EFF;
  }
</style>
